rm(list=ls())

load("TSCS_data.RData")

# Table E.5

panel %>%
  as.data.frame() %>%
  select(country_name,year,downturn) %>%
  mutate(percentile = ntile(downturn, 100),
         upper_cases = if_else(percentile == 100, 'Upper','Lower')) %>%
  filter(upper_cases == 'Upper') %>%
  mutate(country_name = droplevels(country_name)) %>%
  select(-percentile,-upper_cases) %>%
  rename(Country = country_name,
         Year = year,
         Downturn = downturn) ->
  country_upper

write.csv(country_upper, file = "tab_e5.csv", row.names = F)